<template>
  <div>
    <FilterTable
      ref="table"
      columnsRef="repairQueryStatisticsHoursStatisticsSummary"
      :columns="columns"
      :dataSource="dataSource"
      :isExportExcel="true"
      height="450px"
      exportFileName="工时统计汇总.xlsx"
      :isMemoryPagination="true"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChangeHandle"
      :onSyncTableData="tableAllData"
    >
      <template slot="controls" slot-scope="props"> </template>
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 99,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">关 闭</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
import dictCode from '@/utils/dictCode';
import { arrayObjDeWeight } from '@/utils/index'; // 去重
import { getDealerUser } from '@/api/customerRepair/customerComplaint/customerComplaintReception';
import { searchWorkingHoursSum } from '@/api/repair/queryStatistics/queryAccounts';
export default {
  name: 'LHMHoursStatisticsSummary',
  components: {},
  mixins: [dictionary],
  props: ['formData'],
  data() {
    return {
      dataSource: [],
      columns: this.createTableCheckColumns()
    };
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.BaseTable.START_LOADING();
    this.searchWorkingHoursSum();
    this.getDealerUser();
  },
  methods: {
    createTableCheckColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '主修人',
          dataIndex: 'TECHNICIAN',
          sorter: true,
          showOverflowTooltip: true,
          editable: false,
          editType: 'select',
          editItems: [],
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        {
          title: '车次',
          dataIndex: 'countss',
          sorter: true,
          filter: true,
          align: 'center',
          summation: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '台次',
          dataIndex: 'counts',
          sorter: true,
          filter: true,
          align: 'center',
          summation: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '工时',
          dataIndex: 'STD_LABOUR_HOUR',
          sorter: true,
          filter: true,
          align: 'right',
          precision: 2,
          summation: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          filter: true,
          align: 'right',
          precision: 2,
          summation: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '优惠后工时费',
          dataIndex: 'REAL_AMOUNT',
          sorter: true,
          filter: true,
          align: 'right',
          precision: 2,
          summation: true,
          showOverflowTooltip: true,
          filterType: 'number'
        }
      ];
    },
    // 获取所有人的信息
    async getDealerUser() {
      const res = await getDealerUser();
      let userData = arrayObjDeWeight(res.data, 'userId');
      this.columns.find(x => x.dataIndex == 'TECHNICIAN').dictItems = this.columns.find(x => x.dataIndex == 'TECHNICIAN').filterItems = this.columns.find(
        x => x.dataIndex == 'TECHNICIAN'
      ).editItems = userData.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      }));
    },
    async searchWorkingHoursSum() {
      try {
        let formData = JSON.parse(JSON.stringify(this.formData));
        formData.workgroupCode && (formData.workgroupCode = formData.workgroupCode.join(','))
        console.log(formData.workgroupCode);
        let res = await searchWorkingHoursSum(formData);
        if (res.resultCode == 200) {
          console.log('res', res);
          this.dataSource = res.data;
        }
      } catch (error) {
      } finally {
        this.BaseTable.STOP_LOADING();
      }
    },
    tableAllData(val) {},
    selectChangeHandle(val) {
      this.selectedRow = val;
    },
    closeDialog() {
      this.$emit('close', false);
    }
  }
};
</script>
<style lang="less" scoped></style>
